<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>红包列表</title>
    <link rel="stylesheet" type="text/css" th:href="@{/js/layui/css/layui.css}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/style.css/}" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/css/fyn/my.css/}" media="all">
    <style>
        .layui-tab-item {
            height: 0;
            visibility: hidden;
            display: inherit !important;
        }

        .layui-show {
            height: calc(100% - 15px);
            visibility: visible;
        }
    </style>
</head>
<body class="body">

<script type="text/html" id="topOperate">
    <div class="my-btn-box layui-form">
        <!--<span class="fl"> -->
        <!--<button class="layui-btn layui-btn-sm" lay-event="toSave"><i-->
        <!--class="layui-icon"></i>添加用户</button>-->
        <!--</span>-->

    </div>
</script>

<div class="my-btn-box layui-form">
    <span class="fr">
        <div class="layui-input-inline">
            <select class="layui-select" lay-filter="type">
                 <option value="">选择红包类型</option>
                 <option value="0">单聊</option>
                 <option value="1">群聊</option>
            </select>
        </div>
        <div class="layui-input-inline">
            <input type="text" autocomplete="off" name="name" placeholder="搜索用户ID" class="layui-input height33">
        </div>
        <button class="layui-btn layui-btn-sm" id="search"><i class="layui-icon">&#xe615;</i></button>
    </span>
</div>

<!-- 表格 -->
<div id="dateTable" lay-filter="event"></div>
<div class="height50"></div>
<script th:src="@{/js/layui/layui.js}"></script>
<!--<script th:src="@{/js/fyn/index.js}"></script>-->
<script th:src="@{/js/fyn/my.js}"></script>
<!--<script type="text/javascript" th:src="@{/js/vip/vip_comm.js}"></script>-->
<!--<script type="text/javascript" th:src="@{/js/vip/vip_table.js}"></script>-->
<script type="text/javascript" th:inline="javascript">

    // layui方法
    layui.use(['table', 'form', 'laypage', 'layer'], function () {

        // 操作对象
        var form = layui.form
            , table = layui.table
            , layer = layui.layer
            , $ = layui.jquery;

        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , height: "full"    //容器高度
            // , skin: 'line'
            , even: 'true'
            , cols: [[                  //标题栏
                {
                    field: 'user.id', title: '红包ID', minWidth: '80', align: 'center', templet: function (d) {
                    return d.packet.id;
                }
                }
                ,
                {
                    field: 'user.id', title: '类型', minWidth: '100', align: 'center', templet: function (d) {
                    return d.packet.type == 0 ? '单聊' : '群聊';
                }
                }
                ,
                {
                    field: 'user.id', title: '发送人ID', minWidth: '100', align: 'center', templet: function (d) {
                    return d.packet.userId;
                }
                }
                ,
                {
                    field: 'user.id', title: '发送人', minWidth: '100', align: 'center', templet: function (d) {
                    return d.sendName;
                }
                }
                ,
                {
                    field: 'user.id', title: '金额', minWidth: '80', align: 'center', templet: function (d) {
                    return d.packet.money;
                }
                }
                ,
                {
                    field: 'user.id', title: '领取金额', minWidth: '80', align: 'center', templet: function (d) {
                        return d.receiveMoney || 0;
                    }
                }
                ,
                {
                    field: 'user.id', title: '总份数', minWidth: '80', align: 'center', templet: function (d) {
                        return d.packet.num;
                    }
                }
                ,
                {
                    field: 'user.id', title: '领取比例（份数）', minWidth: '80', align: 'center', templet: function (d) {
                    return d.receiveCount + " / " + d.packet.num;
                }
                }
                , {
                    field: 'user.username', title: '状态', align: 'center', minWidth: '100', templet: function (d) {
                        if (d.packet.overStatus == 1) {
                            return "领取完";
                        }

                        if (d.packet.type == 0 && d.packet.status == 1) {
                            return "领取完";
                        }

                        if (d.packet.status == 3) {
                            return "已超时";
                        }

                        return "未领完";
                    }
                }

                , {
                    field: 'user.ctime',
                    align: 'center',
                    title: '创建时间',
                    sort: true,
                    minWidth: '200',
                    templet: function (d) {
                        return new Date(d.packet.ctime).Format("yyyy-MM-dd hh:mm:ss");
                    }
                }
                , {
                    title: '操作', align: 'center', templet: function (d) {
                        return "<i class=\"layui-icon layui-icon-group\" style=\"cursor: pointer\" lay-event=\"groupMember\" title=\"领取列表\"></i>";
                    }
                } //这里的toolbar值是模板元素的选择器
            ]]
            , id: 'dataCheck'
            , url: [[${basePath}]] + '/packet/list'
            , method: 'get'
            , page: true
            , limits: [10, 30, 60, 90, 150, 300]
            , toolbar: '#topOperate'
            , limit: 10 //默认采用0
            , loading: true
            // , where: {name: $("input[name='name']").val()}
            , done: function (res, curr, count) {
                //如果是异步请求数据方式，res即为你接口返回的信息。
                //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                $("td[data-field='content']").each(function () {
                    $(this).find(".layui-table-cell").removeClass('layui-table-cell');
                });


            }
        });


        //头工具栏事件
        table.on('toolbar(event)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;

            switch (obj.event) {
                case 'toSave':
                    layer.open({
                        type: 2,
                        title: '用户增加',
                        shadeClose: true,
                        shade: 0.2,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['650px', '550px'],
                        content: [[${basePath}]] + '/user/save/index'
                    });
                    break;
            }
        });

        table.on('tool(event)', function (obj) {
            var data = obj.data;
            if (obj.event === 'groupMember') {
                layer.open({
                    type: 2,
                    title: '领取列表',
                    shadeClose: true,
                    shade: 0.2,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['1000px', '550px'],
                    content: [[${basePath}]] + '/packet/receive/index?id=' + data.packet.id
                });

            }

            if (obj.event === 'updateS') {

                layer.confirm("确定" + (data.user.status == 0 ? "暂停(账号不能再登陆)" : "开启") + "账号状态?", {
                    icon: 3,
                    title: '提示'
                }, function (index) {
                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/user/status/update",
                        data: {id: data.user.id},
                        success: function (res) {
                            if (res.success) {
                                layer.msg("操作完成", {icon: 1});
                                setTimeout(function () {

                                }, 1500);
                                layer.close(index);

                                tableIns.reload();
                            }
                        }
                    });


                }, function (index) {
                    console.log(data.user.status);
                    obj.update({
                        status: "1111"
                    });

                });
            }

            if (obj.event === 'reset') {

                layer.confirm('确定重置此账号密码?', {icon: 3, title: '提示'}, function (index) {

                    $.ajax({
                        type: "post",
                        url: [[${basePath}]] + "/user/password/reset",
                        data: {id: data.user.id},
                        success: function (data) {
                            if (data.success) {
                                layer.msg("重置密码成功！", {icon: 1});

                            }
                        }
                    });


                    layer.close(index);
                });

            }
        });

        var type=null;
        form.on('select(type)', function(data){
            console.log(data.elem); //得到select原始DOM对象
            type=(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
        });




        $("#search").click(function () {
            tableIns.reload({
                where: {
                    userId: $("input[name='name']").val(),
                    type: type
                },
                page: {
                    curr: 1
                }
            });
        })


    });
</script>
<!-- 表格操作按钮集 -->
<script type="text/html" id="barOption">

</script>
</body>
</html>